package com.huabo.sql.record;

import java.lang.reflect.Method;

/**
 * 结果集返回表结构
 * Created by Jackie Liu on 2017/8/20.
 */
public class TableColumn {

    private String fieldName;
    private String columnName;
    private Class<?> javaType;
    //private String fieldGetMethodName;
    //private String fieldSetMethodName;
    private Method fieldGetMethod;
    private Method fieldSetMethod;
    private boolean isTransient = false;
    private boolean isPrimaryKey = false;
    private ExtendType extendType;

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public Class<?> getJavaType() {
        return javaType;
    }

    public void setJavaType(Class<?> javaType) {
        this.javaType = javaType;
    }

    public Method getFieldGetMethod() {
        return fieldGetMethod;
    }

    public void setFieldGetMethod(Method fieldGetMethod) {
        this.fieldGetMethod = fieldGetMethod;
    }

    public Method getFieldSetMethod() {
        return fieldSetMethod;
    }

    public void setFieldSetMethod(Method fieldSetMethod) {
        this.fieldSetMethod = fieldSetMethod;
    }

    public boolean isTransient() {
        return isTransient;
    }

    public void setTransient(boolean aTransient) {
        isTransient = aTransient;
    }

    public boolean isPrimaryKey() {
        return isPrimaryKey;
    }

    public void setPrimaryKey(boolean primaryKey) {
        isPrimaryKey = primaryKey;
    }

    public ExtendType getExtendType() {
        return extendType;
    }

    public void setExtendType(ExtendType extendType) {
        this.extendType = extendType;
    }

    public String getPlaceholder() {
        if (extendType != null) {
            return extendType.getPlaceholder();
        }
        return "?";
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("TableColumn{");
        sb.append("fieldName='").append(fieldName).append('\'');
        sb.append(", columnName='").append(columnName).append('\'');
        sb.append(", javaType=").append(javaType);
        sb.append(", fieldGetMethod=").append(fieldGetMethod);
        sb.append(", fieldSetMethod=").append(fieldSetMethod);
        sb.append(", isTransient=").append(isTransient);
        sb.append(", isPrimaryKey=").append(isPrimaryKey);
        sb.append(", extendType=").append(extendType);
        sb.append('}');
        return sb.toString();
    }
}
